<?php
class Brand extends Model {
	public function addBrand($data) {
		return $this->dbo->query("INSERT INTO manufacturer (name,image,sort_order) VALUES('".$this->dbo->escape($data['name'])."','".$this->dbo->escape($data['image'])."','".(int)$this->dbo->escape($data['sort_order'])."')");
	}
	public function getBrandList(){
		$result = $this->dbo->query("SELECT manufacturer_id,name,sort_order FROM manufacturer ORDER BY sort_order");
		return $result->rows;
	}
	public function getBrandById($id){
		$result = $this->dbo->query("SELECT manufacturer_id,name,sort_order,image FROM manufacturer WHERE manufacturer_id='".(int)$id."'");
		return $result->row;
	}
	public function delBrandByIds($ids){
		return $this->dbo->query("DELETE FROM manufacturer WHERE manufacturer_id IN ($ids)");
	}
	public function getBrandImageByIds($ids){
		$result = $this->dbo->query("SELECT image FROM manufacturer WHERE manufacturer_id IN($ids)");
		return $result->rows;
	}
	public function updateBrand($data){
		$sql="UPDATE manufacturer SET name='".$this->dbo->escape($data['name'])."',";
		if(isset($data['image'])){
			$sql .="image='".$this->dbo->escape($data['image'])."',";
		}
		$sql .="sort_order='".(int)$this->dbo->escape($data['sort_order'])."' WHERE manufacturer_id ='".(int)$this->dbo->escape($data['id'])."'";
		return $this->dbo->query($sql);
	}
}
?>